<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/boot.js"></script>
</head>

<body>
    <div class="layui-fluid">
        <div class="flexrow">
            <div class="layui-panel list-container">
                <div class="list-search-container">
                    <button class="layui-btn layui-btn-sm" onclick="HandleAdd()"><i class="layui-icon layui-icon-add-1 layui-font-12"></i>上传附件</button>
                    <div class="list-search-item">
                        <span>附件名称：</span>
                        <input id="attach_name" autocomplete="off" class="layui-input">
                    </div>
                    <div class="list-search-item">
                        <span>分组标识：</span>
                        <input id="group_guid" autocomplete="off" class="layui-input">
                    </div>
                    <div class="list-search-item">
                        <span>分类标识：</span>
                        <input id="group_type" autocomplete="off" class="layui-input">
                    </div>
                    <button class="layui-btn layui-btn-sm" style="margin-left:5px" onclick="BindTableData()"><i class="layui-icon layui-icon-search layui-font-12"></i>搜索</button>
                </div>
                <table class="layui-table" lay-data="{id: 'datagrid'}" lay-filter="datagrid">
                    <thead>
                        <tr>
                            <th lay-data="{field:'attach_name'}">附件名称</th>
                            <th lay-data="{field:'attach_type',width:120,align:'center'}">附件类别</th>
                            <th lay-data="{field:'group_guid',width:300,align:'center'}">分组标识</th>
                            <th lay-data="{field:'group_type',width:150,align:'center'}">分类标识</th>
                            <th lay-data="{field:'attach_storage_type',width:150,align:'center'}">存储方式</th>
                            <th lay-data="{field:'upload_user_name',width:100,align:'center'}">上传人</th>
                            <th lay-data="{field:'gmt_create',width:200,align:'center'}">上传时间</th>
                            <th lay-data="{fixed: 'right', width:200, align:'center', toolbar: '#op'}">操作</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</body>
<script type="text/html" id="op">
    <button class="layui-btn layui-btn-sm" lay-event="HandleDownLoad"><i class="layui-icon layui-icon-download-circle layui-font-12"></i>下载</button>
    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="HandleDelete"><i class="layui-icon layui-icon-delete layui-font-12"></i>删除</button>
</script>
<script>
    $(function() {
        BindTableData();
    })

    function BindTableData() {
        var param = {
            attach_name: $("#attach_name").val(),
            group_guid: $("#group_guid").val(),
            group_type: $("#group_type").val(),
        }
        BindTable("datagrid", "system/common/attach/manageList", param);
    }

    function HandleAdd() {
        OpenDialog('上传附件', 'system/attach/attach_add.html', 800, 600, function() {
            BindTableData();
        })
    }

    function HandleDownLoad(RowData) {
        var downloadUrl = GetApiPath() + "system/common/attach/download?row_id=" + RowData.row_id;
        window.open(downloadUrl)
    }

    function HandleDelete(RowData) {
        OpenConfirm('确认删除？', function() {
            var param = {
                row_id: RowData.row_id
            }
            HttpPost(JSON.stringify(param), 'system/common/attach/delete', function(result) {
                if (result.code == 0) {
                    OpenSuccessMessage("删除成功")
                    BindTableData();
                } else {
                    OpenFail(result.msg);
                }
            })
        })
    }
</script>

</html>